<extend name="Base:main" />
<block name="script">
    <script src="__PUBLIC__/seller/js/calendar/WdatePicker.js"></script>
</block>
<block name="content">
	<style>
		.tpl-portlet-components{ border:none }
	</style>
    <div class="tpl-content-wrapper">
            <div class="tpl-content-page-title">
                商品管理
            </div>
            <ol class="am-breadcrumb">
                <li><a href="#" class="am-icon-home">首页</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="am-active">供应商品信息修改</li>
            </ol>
            <div class="tpl-portlet-components">
                <div class="portlet-title">
                      <div class="caption font-green bold">
                        <span class="am-icon-code"></span>供应信息修改
                    </div>
                </div>
				<div class="tpl-block ">
					<div class="am-g tpl-amazeui-form">
						<div class="am-u-sm-12 am-u-md-12">
							<div class="am-form-group">
								<div class="am-u-sm-12">
									<fieldset class="fieldset_list">
										<legend>仓库保存费用说明</legend>
										<div class="supply_info">
											<dl>
												<dt>总量：</dt>
												<dd>{:weight_unit_conversion( $data['storage_overdue_rule']['weight'] )}</dd>
											</dl>
											<dl>
												<dt>金额：</dt>
												<dd>{:number_format( $data['storage_overdue_rule']['price'] , 2 , '.' , ',' )}</dd>
											</dl>
											<dl style="width:100%; color:red;">
												<dd>备注：总量和金额都是按照每天来计算</dd>
											</dl>
										</div>
									</fieldset>
									<fieldset class="fieldset_list">
										<legend>支付信息</legend>
										<div class="supply_info">
											<dl>
												<dt>预期时间：</dt>
												<dd>{:surplus_storage_time($data['storage_end_time'])}</dd>
											</dl>
											<dl>
												<dt>预期保管费：</dt>
												<dd>{:number_format( $data['expect_price'] , 2 , '.' , ',' )}</dd>
											</dl>
											
											<dl style="width:100%; margin-top:10px;">
												<dt>存储时间：</dt>
												<dd><input type="text" id="save_day" onclick="WdatePicker({onpicking:function(dq){selectDatediff(dq.cal.getNewDateStr());},isShowClear:false,minDate:'<?php echo $start_time_date ?>'})" style="width:150px; padding:4px 8px; border:1px solid #ccc"/> </dd>
											</dl>
											<dl style="width:100%; margin-top:10px;">
												<dt>存储费用：</dt>
												<dd><span style="font-weight:bold; font-size:20px; color:red;" id="save_price">0.00</span> <span style="font-size:12px;">元</span></dd>
											</dl>
											<dl style="width:100%; margin-top:10px;">
												<dd><span style="color:red">注意：可以不续加存储时间，只支付预期保管费。但没有预保存费，产品的业务会受到极大的影响</span></dd>
											</dl>
											<dl style="width:100%; margin-top:10px;">
												<dd>合计总共支付：<span style="font-weight:bold; font-size:20px; color:red;" id="pay_total_price">0.00</span> <span style="font-size:12px;">元</span></dd>
											</dl>
											<dl style="width:100%; margin-top:10px;">
												<dt>支付方式：</dt>
												<dd>
													<?php if($payInfo['weixin_pay_id']>0):?>
													<label><input name="pay" id="pay" type="radio" value="{$payInfo['weixin_pay_id']}"  />&nbsp;&nbsp;微信 </label> &nbsp;&nbsp;&nbsp;
													<?php endif;?>
													<?php if($payInfo['alipay_pay_id']>0):?>
													<label><input name="pay" id="pay" type="radio" value="{$payInfo['alipay_pay_id']}"  />&nbsp;&nbsp;支付宝 </label> &nbsp;&nbsp;&nbsp;
													<?php endif;?>
													<label><input name="pay" id="pay" type="radio" value="preset"  />&nbsp;&nbsp;预付款 </label> 
												</dd>
											</dl>
											<dl style="display:none;width:100%;" id="money">
												<dt>账户余额：</dt>
												<dd><span style="font-size:14px">￥{:sprintf("%.2f",$local_price)}</span> <span style="font-size:12px;">元</span></dd>
											</dl>
										</div>
									</fieldset>
								</div>
							</div>

							<div class="am-form-group">
								<div class="am-u-sm-9 am-u-sm-push-3">
									<button type="button" id="submit_pay" class="am-btn am-btn-primary">确认支付</button>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
        </div>
	<script>
		var day_price = {$data.goods_price};
		var export_price = {$data['expect_price']};
		var total_price = export_price;
		$('#pay_total_price').text( formatMoney( export_price , 2, "￥") );
		function selectDatediff(str) {
			var day_time = datedifference('<?php echo $start_time; ?>' , str);
			$('#save_price').text( formatMoney( ( day_time * day_price ) , 2, "￥") );
			total_price = ( day_time * day_price + export_price );
			$('#pay_total_price').text( formatMoney( total_price , 2, "￥") );
		}
		$('#submit_pay').click(function(){
			var id = "<?php echo $data['id'];?>";
			var save_day = $('#save_day').val();
			if($('input#pay:checked').length >0){
				if( total_price <= 0 ) {
					error( '支付金额不能为0' );
					return false;
				}
				if( $('input#pay:checked').val() == 'preset' ) {
					<?php if( $local_price == '0.00' ) : ?>
					error('账户金额不足,请充值之后再支付');
					return false;
					<?php else : ?>
					if( parseFloat({$local_price}) < parseFloat(total_price) ) {
						error('账户金额不足,请充值之后再支付');
						return false;
					}
					<?php endif;?>
				}
				var order_id = 0;
				var wait_index = waitload('正在下单，请稍等...');
				$.ajax({
					dataType : 'json',
					data : {id : id , date : save_day,'pay_id' : $('input#pay:checked').val()},
					url : '{:U('Goods/warehouseStorageOrder')}',
					async : false,
					type : 'get',
					success : function(data) {
						zeroModal.close(wait_index);
						if( data.status == 1 ) {
							zeroModal.confirm({
								content: '支付成功了吗？',
								buttons: [
									{ className: 'zeromodal-btn zeromodal-btn-primary', name: '支付成功', fn:function(opt){ location.href="{:U('Goods/distribution',array('type' => 'lock'))}" }},
									{ className: 'zeromodal-btn zeromodal-btn-default', name: '失败了', fn:function(opt){ $('#pay_cusomter').click(); }}
								]
							});
							order_id = data.data;
							flag = true;
						} else {
							error('下单失败，请重新下单');
						}
					}
				});
				if( order_id > 0 ) {
					window.open(getUrl('Pay/pay' , { 'id':order_id , 'type' : 'warehouse' , 'pay_id' : $('input#pay:checked').val() }));
				}
			}else{
				error('请选择支付方式');
			}
		});
		$('input#pay').click(function(){
			if( $(this).val() == 'preset' ) {
				$('#money').show();
			} else {
				$('#money').hide();
			}
		});
	</script>
</block>